﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace VikingArcade_v2._0
{
    public class TextBoxDrawer : UserInterfaceControlDrawer
    {
        private TextBox textBox;

        public TextBoxDrawer(TextBox textBox) : base(textBox)
        {
            this.textBox = textBox;
        }
        
        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            if (textBox.Visible)
            {
                if (textBox.Font == null)
                {
                    throw new ArgumentNullException("Font not set");
                }

                string textToDraw = textBox.Text;

                while (textBox.Font.MeasureString(textToDraw).Y > textBox.Size.Y)
                {
                    textToDraw = textToDraw.Substring(1);
                }

                spriteBatch.DrawString(textBox.Font, textToDraw, new Vector2(textBox.AbsolutePosition.X, textBox.AbsolutePosition.Y), textBox.ForeColor);

            }
        }
    }
}
